﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="/logout">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="/index" class="index_on"></a></li>
                <li><a href="/rolelist" class="role_off"></a></li>
                <li><a href="/adminList" class="admin_off"></a></li>
                <li><a href="/feelist" class="fee_off"></a></li>
                <li><a href="/accountlist" class="account_off"></a></li>
                <li><a href="/servicelist" class="service_off"></a></li>
                <li><a href="/billList" class="bill_off"></a></li>
                <li><a href="/reportList" class="report_off"></a></li>
                <li><a href="/userInfo" class="information_off"></a></li>
                <li><a href="/userModiPwd" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">
            <!--保存操作的提示信息-->
            <div id="save_result_info" class="save_fail">资费修改失败！数据并发错误。</div>
            <form action="" method="" class="main_form">
                <!--必填项-->
                <div class="text_info clearfix"><span>业务账号ID：</span></div>
                <div class="input_info">
                    <input type="text" id="serviceId" readonly class="readonly"/>
                </div>
                <div class="text_info clearfix"><span>OS 账号：</span></div>
                <div class="input_info">
                    <input type="text" id="osUsername" readonly class="readonly"/>
                </div>
                <div class="text_info clearfix"><span>服务器 IP：</span></div>
                <div class="input_info">
                    <input type="text" id="unixHost" readonly class="readonly"/>
                </div>
                <div class="text_info clearfix"><span>资费类型：</span></div>
                <div class="input_info">
                    <select class="width150" id="select">
                    </select>
                    <div class="validate_msg_long">请修改资费类型，或者取消修改操作。</div>                      
                </div>
                <!--操作按钮-->
                <div class="button_info clearfix">
                    <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                    <input type="button" value="取消" class="btn_save" onclick="cancel();"/>
                </div>

                
                <p>业务说明：<br />
                1、修改资费后，点击保存，并未真正修改数据库中的数据；<br />
                2、提交操作到消息队列；<br />
                3、每月月底由程序自动完成业务所关联的资费；</p>
                
            </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)云科技有限公司 </span>
        </div>
        <script src="../../js/jquery-3.2.1.js"></script>
        <script src="../../js/GetQueryString.js"></script>
        <script>
            var serviceId = GetQueryString('serviceId');
            function cancel() {
                if(confirm("修改尚未保存，是否取消")){
                    window.location.href = "/servicelist";
                }
            }
            $.ajax({
                url: "/findServiceById",
                type: "post",
                data: {
                    serviceId: serviceId
                },
                success: function (data) {
                    for (var i in data) {
                        var service = data[i];
                        var osUsername = service.osUsername;
                        var unixHost = service.unixHost;
                        $("#serviceId").val('' + serviceId + '');
                        $("#osUsername").val('' + osUsername + '');
                        $("#unixHost").val('' + unixHost + '');
                    }
                }
            });
            $.ajax({
                url: "/listservice",
                type: "post",
                success: function (data) {
                    for (var i in data) {
                        var service = data[i];
                        for (var j in service.cList) {
                            var cList = service.cList[j];
                            var name = cList.name;
                            $("#select").append("<option>" + name + "</option>");
                        }
                    }
                }
            });
            //保存成功的提示信息
            function showResult() {
                var serviceId = $("#serviceId").val();
                //var osUsername=$("#osUsername").val();
                //var unixHost=$("#unixHost").val();
                var name = $("#select option:selected").text();
                $.ajax({
                    url: "/selectCostIdByName",
                    type: "post",
                    data: {
                        name: name
                    },
                    success: function (data) {
                        var costId = null;
                        for (var i in data) {
                            var list = data[i];
                            costId = list.costId;
                        }
                        $.ajax({
                            url: "/updateCostIdByServiceId",
                            type: "post",
                            data: {
                                costId: costId,
                                serviceId: serviceId
                            },
                            success: function () {
                                window.location.href = "/servicelist";
                            },
                            error: function () {
                                showResultDiv(true);
                                window.setTimeout("showResultDiv(false);", 3000);
                            }
                        });
                    }
                });
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
        </script>
    </body>
</html>
